package com.hyc.provider;

import com.hyc.rateLimit.AsyncTokenBucketRateLimiter;
import com.hyc.rateLimit.RateLimit;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 冷环渊
 * @date 2025/6/10 14:22
 * @description RateLimitProvider
 */
public class RateLimitProvider {
    //用于存储每个节点和限流器的映射关系
    private Map<String, RateLimit> rateLimitMap = new ConcurrentHashMap<>();

    public RateLimit getRateLimitByInterfaceName(String interfaceName) {
        return rateLimitMap.computeIfAbsent(interfaceName, k ->
                new AsyncTokenBucketRateLimiter(1, 1));
    }
}
